﻿using AutoMapper;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using CRM.Admin.Contracts.Model.Map;
using KingsSharp.Common.Extensions;
using KingsSharp.Core;

namespace CRM.Admin.Services.Mappers
{
    public class CustomerMapper : IMapper
    {
        public void Register()
        {
            //顾客基本信息
            Mapper.CreateMap<CustomerDto, Customer>();
            Mapper.CreateMap<Customer, CustomerDto>();

            //顾客简介
            Mapper.CreateMap<CustomerProfilesDto, CustomerProfiles>();
            Mapper.CreateMap<CustomerProfiles, CustomerProfilesDto>();

            //顾客履历配置
            Mapper.CreateMap<ResumeConfigDto, ResumeConfig>();
            Mapper.CreateMap<ResumeConfig, ResumeConfigDto>();

            //顾客履历
            Mapper.CreateMap<CustomerResumeDto, CustomerResume>();
            Mapper.CreateMap<CustomerResume, CustomerResumeDto>();

            //顾客性质基础主表
            Mapper.CreateMap<NatureCatalogDto, NatureCatalog>();
            Mapper.CreateMap<NatureCatalog, NatureCatalogDto>();

            //顾客性质基础子表
            Mapper.CreateMap<NatureDto, Nature>();
            Mapper.CreateMap<Nature, NatureDto>();

            //顾客协议
            Mapper.CreateMap<CustomerAgreementDto, CustomerAgreement>();
            Mapper.CreateMap<CustomerAgreement, CustomerAgreementDto>();
            //顾客性质
            Mapper.CreateMap<CustomerNatureDto, CustomerNature>();
            Mapper.CreateMap<CustomerNature, CustomerNatureDto>();

            //顾客地址
            Mapper.CreateMap<CustomerAddressDto, CustomerAddress>();
            Mapper.CreateMap<CustomerAddress, CustomerAddressDto>();

            //顾客联系人
            Mapper.CreateMap<LinkManDto, LinkMan>();
            Mapper.CreateMap<LinkMan, LinkManDto>();

            //顾客归属
            Mapper.CreateMap<AscriptionDto, Ascription>();
            Mapper.CreateMap<Ascription, AscriptionDto>()
                .ForMember(a => a.OrganizationName, opt => opt.MapFrom(b => b.Organization != null ? b.Organization.Name : ""));

            //生产工艺
            Mapper.CreateMap<TechnologyDto, Technology>();
            Mapper.CreateMap<Technology, TechnologyDto>()
                .ForMember(a => a.EquipmentGetDate,
                    opt => opt.MapFrom(b => b.EquipmentGetDate.HasValue ? b.EquipmentGetDate.Value.ToShortDate() : ""))
                .ForMember(a => a.ProcessGetDate,
                    opt => opt.MapFrom(b => b.ProcessGetDate.HasValue ? b.ProcessGetDate.Value.ToShortDate() : ""));

            //竞争对手情况
            Mapper.CreateMap<CompetitorDto, Competitor>();
            Mapper.CreateMap<Competitor, CompetitorDto>();



            //产品
            Mapper.CreateMap<ProductDto, Product>();
            Mapper.CreateMap<Product, ProductDto>();

            //零件
            Mapper.CreateMap<ComponentDto, Component>();
            Mapper.CreateMap<Component, ComponentDto>();

            //服务管理
            Mapper.CreateMap<ServeMgDto, ServeMg>();
            Mapper.CreateMap<ServeMg, ServeMgDto>()
                     .ForMember(a => a.StartDate,
                    opt => opt.MapFrom(b => b.StartDate.HasValue ? b.StartDate.Value.ToShortDate() : ""))
                .ForMember(a => a.EndDate,
                    opt => opt.MapFrom(b => b.EndDate.HasValue ? b.EndDate.Value.ToShortDate() : ""));

            //钢厂
            Mapper.CreateMap<SteelDto, Steel>();
            Mapper.CreateMap<Steel, SteelDto>();

            //采购渠道
            Mapper.CreateMap<PurchaseDto, Purchase>();
            Mapper.CreateMap<Purchase, PurchaseDto>();


            //品种需求
            Mapper.CreateMap<VarietyDto, Variety>();
            Mapper.CreateMap<Variety, VarietyDto>();

            //品种年需求
            Mapper.CreateMap<VarietyYearDto, VarietyYear>();
            Mapper.CreateMap<VarietyYear, VarietyYearDto>();


            //需求情况-按地区
            Mapper.CreateMap<AreaRequstDto, AreaRequstInfo>();
            Mapper.CreateMap<AreaRequstInfo, AreaRequstDto>();


            //需求情况按行业
            Mapper.CreateMap<IndustryRequstDto, IndustryRequstInfo>();
            Mapper.CreateMap<IndustryRequstInfo, IndustryRequstDto>();


            //需求情况按终端用户
            Mapper.CreateMap<UserRequstDto, UserRequstInfo>();
            Mapper.CreateMap<UserRequstInfo, UserRequstDto>();


            //供给情况
            Mapper.CreateMap<SupplyDto, SupplyInfo>();
            Mapper.CreateMap<SupplyInfo, SupplyDto>();


            //网店简介
            Mapper.CreateMap<NetworkDto, NetworkInfo>();
            Mapper.CreateMap<NetworkInfo, NetworkDto>();

            //销售流向
            Mapper.CreateMap<SaleDto, SaleInfo>();
            Mapper.CreateMap<SaleInfo, SaleDto>();

            //简介
            Mapper.CreateMap<AreaProfilesDto, AreaProfilesInfo>();
            Mapper.CreateMap<AreaProfilesInfo, AreaProfilesDto>();

            //推广计划
            Mapper.CreateMap<PromotionPlanDto, PromotionPlan>();
            Mapper.CreateMap<PromotionPlan, PromotionPlanDto>();
        }
    }
}
